Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction "SilentlyContinue"

$location = [Environment]::CurrentDirectory=(Get-Location -PSProvider FileSystem).ProviderPath
$solutionName = "EFSBWFActivities.getMultiLookupFromStringSB.wsp"
$SiteCollectionUrl = "http://hvsp2010a/sites/CallCentre"

$sol = Get-SPUserSolution -Site $SiteCollectionUrl | Where-Object {$_.Name -eq $solutionName}

Write-Host " "
if($sol -eq $null)
{
	Add-SPUserSolution -LiteralPath $location\$solutionName -Site $SiteCollectionUrl
	write-host "Adding $($solutionName) ..." -NoNewline
	do 
	{ 
		Write-Host "." -NoNewline
		Start-Sleep 1
	}
	while ((Get-SPUserSolution -Identity $solutionName -Site $SiteCollectionUrl).JobExists -eq $true)
	Write-Host "ok"
}
else
{
	Write-Host "Solution $($solutionName) already installed"
}

$sol = Get-SPUserSolution -Site $SiteCollectionUrl | Where-Object {$_.Name -eq $solutionName}
if ($sol -ne $null) {
	if($sol.Status -eq "Activated")
	{	
		Write-Host "Solution $($solutionName) already deployed."
	}
	else
	{
		Install-SPUserSolution -Identity $solutionName -Site $SiteCollectionUrl
		write-host "Installing $($solutionName) ..." -NoNewline
		do 
		{ 
			Write-Host "." -NoNewline
			Start-Sleep 1
		}
		while ((Get-SPUserSolution -Identity $solutionName -Site $SiteCollectionUrl).JobExists -eq $true)
		Write-Host "ok"
	}
}
else
{
	Write-Host "Solution $($solutionName) was not installed, cannot deploy."
}
Write-Host " "
Write-Host "*** Installation finished ***"
Write-Host " "
Write-Host "Completed.  Any key to exit..."
Read-Host
